<template>
  <div class="login-container">
    <img :src="logo" alt="" class="logo" />
    <van-form @submit="onSubmit">
      <van-cell-group inset>
        <van-field
          v-model="username"
          name="用户名"
          placeholder="用户名"
          left-icon="manager"
          clearable=""
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="password"
          left-icon="lock"
          type="password"
          name="密码"
          placeholder="密码"
          clearable=""
          :rules="[{ required: true, message: '请填写密码' }]"
        />
      </van-cell-group>
      <div style="margin: 16px">
        <van-button round block native-type="submit" color="#ef2000">
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { ref } from 'vue'
import logo from '@/assets/logo.png'
import { useRouter } from 'vue-router'
export default {
  setup() {
    const username = ref('')
    const password = ref('')
    const router = useRouter()
    function onSubmit() {
      // 将假的登录数据保存到本地
      sessionStorage.setItem('token', username.value)
      // const { data: res } = await $http.post(
      //   `/login/cellphone?phone=${username.value}&password=${password.value}`
      // )

      // console.log(res)
      router.push('/my')
    }
    return {
      username,
      password,
      logo,
      onSubmit
    }
  }
}
</script>

<style lang="less" scoped>
.login-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 13.34rem;
  background-color: #fff;
  .van-form {
    box-shadow: 0 0 0.2rem rgba(0, 0, 0, 0.5);
    border-radius: 0.4rem;
    width: 80%;
  }
  .logo {
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 0.4rem;
  }
}
</style>
